package com.api.service.impl;

import com.alibaba.druid.util.StringUtils;
import com.api.service.UploadService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class UploadServiceImpl  implements UploadService {

    @Value("${static.domain}")
    private String domain;

    /**
     * 删除域名
     * @param fileUrl
     * @return
     */
    @Override
    public String deleteFile(String fileUrl) {
        if (StringUtils.isEmpty(fileUrl)) { return fileUrl;}
        return fileUrl.replace(domain, "");
    }


    /**
     * 添加域名
     * @param url
     * @return
     */
    @Override
    public String toAbsoluteUrl(String url) {
        if (StringUtils.isEmpty(url)) { return url;}
        return domain + url;
    }
}
